package com.daedalus.Gui.Font;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;


public class Sheet extends JPanel{

	JTextArea paper1,paper2;
	JCheckBox bold;
	JCheckBox italic;
	JRadioButton rBold;
	JRadioButton rItalic;
	JRadioButton boldItalic;
	
	public Sheet(){
		setLayout(null);
		setSize(500,500);
		
		bold=new JCheckBox("BOLD");
		bold.setFont(new Font("SERIF",Font.BOLD,14));
		italic = new JCheckBox("ITALIC");
		italic.setFont(new Font("SERIF",Font.ITALIC,14));
		bold.setLocation(10, 10);
		italic.setLocation(80, 10);
		bold.setSize(70, 30);
		italic.setSize(70, 30);
		add(bold);
		add(italic);
		
		paper1=new JTextArea("Enter text here...");
		paper1.setSize(200, 200);
		paper1.setLocation(10, 50);
		add(paper1);
		paper2=new JTextArea("Enter text even here...");
		paper2.setSize(200, 200);
		paper2.setLocation(240, 50);
		add(paper2);
		
		rBold=new JRadioButton("BOLD");
		rItalic = new JRadioButton("ITALIC");
		rBold.setLocation(230, 10);
		rItalic.setLocation(320, 10);
		rBold.setSize(70, 30);
		rItalic.setSize(70, 30);
		boldItalic=new JRadioButton("BOLD&Italic");
		boldItalic.setLocation(410, 10);
		boldItalic.setSize(110, 30);
		ButtonGroup groupRadio=new ButtonGroup();
		groupRadio.add(rBold);
		groupRadio.add(rItalic);
		groupRadio.add(boldItalic);
		
		add(rBold);
		add(rItalic);		
		add(boldItalic);
		
		fontListener listener = new fontListener();
		bold.addItemListener(listener);
		italic.addItemListener(listener);
		rBold.addItemListener(listener);
		rItalic.addItemListener(listener);
		boldItalic.addItemListener(listener);
	}
	
	private class fontListener implements ItemListener{

		int bld=Font.PLAIN;
		int itl=Font.PLAIN;
		
		@Override
		public void itemStateChanged(ItemEvent e) {
			if (e.getSource()==bold){
				if(e.getStateChange()==ItemEvent.SELECTED)
					bld=Font.BOLD;
				else if(e.getStateChange()==ItemEvent.DESELECTED)
					bld=Font.PLAIN;
			}
			if (e.getSource()==italic){
				if(e.getStateChange()==ItemEvent.SELECTED)
					itl=Font.ITALIC;
				else if(e.getStateChange()==ItemEvent.DESELECTED)
					itl=Font.PLAIN;
			}
			paper1.setFont(new Font("SERIF",bld+itl,14));
			
			if(e.getSource()==rBold){
				paper2.setFont(new Font("SERIF",Font.BOLD,14));
			}
			if(e.getSource()==rItalic){
				paper2.setFont(new Font("SERIF",Font.ITALIC,14));
			}
			if(e.getSource()==boldItalic){
				paper2.setFont(new Font("SERIF",Font.BOLD+Font.ITALIC,14));
			}
			
		}
	}
	
}
